package cn.edu.sgu.www.mhxysy.controller.system;

import cn.edu.sgu.www.mhxysy.consts.CustomConstants;
import cn.edu.sgu.www.mhxysy.consts.CustomMessages;
import cn.edu.sgu.www.mhxysy.consts.MimeTypes;
import cn.edu.sgu.www.mhxysy.dto.system.MenuTreeDTO;
import cn.edu.sgu.www.mhxysy.dto.system.UserMenuDTO;
import cn.edu.sgu.www.mhxysy.restful.JsonResult;
import cn.edu.sgu.www.mhxysy.service.system.UserMenuService;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 沐雨橙风ιε
 * @version 1.0
 */
@Api(tags = "用户菜单管理")
@ApiSupport(author = CustomConstants.AUTHOR)
@RestController
@RequestMapping(path = "/user_menu", produces = MimeTypes.APPLICATION_JSON_CHARSET_UTF_8)
public class UserMenuController {

	private final UserMenuService userMenuService;

	@Autowired
	public UserMenuController(UserMenuService userMenuService) {
		this.userMenuService = userMenuService;
	}

	@ApiOperation("控制菜单显示")
	@RequestMapping(value = "/control", method = RequestMethod.POST)
	public JsonResult<Void> control(MenuTreeDTO menuTreeDTO) {
		userMenuService.control(menuTreeDTO);

		return JsonResult.success(CustomMessages.OPERATE_SUCCESS);
	}

	@ApiOperation("设置菜单排序")
	@RequestMapping(value = "/updateSort", method = RequestMethod.POST)
	public JsonResult<Void> updateSort(@Validated UserMenuDTO userMenuDTO) {
		userMenuService.updateSort(userMenuDTO);

		return JsonResult.success(CustomMessages.UPDATE_SUCCESS);
	}

}